/**
 * Created by liangtao on 2016/9/8.
 */
var generalChartsOptions = {
    generalPie:function (title,subText,legend,seriesData,seriesName) {
        var options = {
            title : {
                text: title,
                subtext: subText,
                x:'center'
            },
            tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                left: 'left',
                data: legend
            },
            toolbox: {
                orient:'vertical',
                show : true,
                feature : {
                    mark : {show: true},
                    dataView : {show: true, readOnly: false},
                    magicType : {
                        show: true,
                        type: ['pie', 'funnel']
                    },
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            series:[
                {
                    name: seriesName,
                    type: 'pie',
                    radius : '55%',
                    center: ['50%', '60%'],
                    label:{
                        normal:{
                            formatter:'{b}: {c}'
                        }
                    },
                    data:seriesData,
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        }
        return options;
    },
    generalLine:function (title,subText,legend,xData,seriesName,seriesData) {
        var options = {
            title: {
                text: title,
                subtext:subText,
                x:'center'
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data:legend,
                top:'10%'
            },
            toolbox: {
                orient:'vertical',
                show: true,
                feature: {
                    dataZoom: {
                        yAxisIndex: 'none'
                    },
                    dataView: {readOnly: false},
                    magicType: {type: ['line', 'bar']},
                    restore: {},
                    saveAsImage: {}
                }
            },
            grid:[
                {y: '20%'}
            ],
            xAxis:  {
                type: 'category',
                boundaryGap: false,
                data: xData
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name:seriesName,
                    type:'line',
                    data:seriesData,
                    markPoint: {
                        data: [
                            {type: 'max', name: '最大值'},
                            {type: 'min', name: '最小值'}
                        ]
                    },
                    markLine: {
                        data: [
                            {type: 'average', name: '平均值'}
                        ]
                    }
                }
            ]
        }
        return options;
    },
    stackedBar:function (title,subText,legend,xData,series) {
        var option = {
            title: {
                text: title,
                subtext:subText,
                x:'center'
            },
            tooltip: {
                trigger: 'axis'
            },
            toolbox: {
                orient:'vertical',
                show: true,
                feature: {
                    dataZoom: {
                        yAxisIndex: 'none'
                    },
                    dataView: {readOnly: false},
                    magicType: {type: ['line', 'bar']},
                    restore: {},
                    saveAsImage: {}
                }
            },
            legend: {
                data:legend,
                top:'10%'
            },
            grid:[
                {y: '22%'}
            ],
            xAxis:  {
                type: 'category',
                axisLabel:{
                    interval:0,
                    rotate:-20
                },
                data: xData
            },
            yAxis: {
                type: 'value'
            },
            series: series
        };
        return option;
    }
}
